/*
  scoreboard.h - Library for SFDB scoreboard.
  Created by Guido Zuliani (zulio), January 14, 2012.
  Released into the public domain.
*/
#ifndef SCOREBOARD_H
#define SCOREBOARD_H

#include <Arduino.h>

const unsigned int DO_NOT_SHOW = 10;

class ScoreBoard
{
  private:
    boolean _need_refresh;
  
    unsigned int _home_score;
    unsigned int _guest_score;
    boolean _arrow_left;
    int _period;
    int _bonus;               // 0:no_bonus 1:home_bonus 2;guest_bonus 3:both_bonus 
  
    //time
    boolean _time_running;
    
    unsigned long _last_millis; //for debug only
    unsigned long _end_time_millis;
    unsigned long _remain_time_millis; 
    int _minutes; 
    int _seconds;
    int _decimals;
 
    void _init();
    void _update_clock(); 
   
    //pointer to a function
    unsigned long (*_func_external_millis)(void);
    //callback
    void (*_func_time_ticker)(void);
    void (*_func_time_ended)(void);
       
 public:
    ScoreBoard();
    ScoreBoard(unsigned long (*funct_external_mills)(void));
    
    //getter
    unsigned long last_millis() {return _last_millis;};
    boolean need_refresh() {return _need_refresh;};
    unsigned int home_score() {return _home_score;};
    unsigned int guest_score() {return _guest_score;};
    boolean arrow_left() {return _arrow_left;};
    int period() {return _period;};
    int bonus() {return _bonus;};
    boolean time_running() {return _time_running;};
    int minutes() {return _minutes;};
    int seconds() {return _seconds;};
    int decimals() {return _decimals;};

    //setter
    void set_need_refresh() {_need_refresh=true;};
    void set_funct_external_mills(unsigned long (*funct_external_mills)(void));
    void set_func_time_ticker(void (*func_time_ticker)(void)) {_func_time_ticker=func_time_ticker;};
    void set_func_time_ended(void (*func_time_ended)(void)) {_func_time_ended=func_time_ended;};
    
    //monitor changes
    void values_read() {_need_refresh=false;};
    
    //score
    void add_home_score(int val);
    void add_home_score() {add_home_score(1);};
    void add_guest_score(int val);
    void add_guest_score() {add_guest_score(1);};
    void sub_home_score(int val);
    void sub_home_score(){sub_home_score(1);};
    void sub_guest_score(int val);       
    void sub_guest_score() {sub_guest_score(1);};    
    
    //bonus, arrow, period
    void change_bonus();
    void change_arrow();
    void change_period();
    
    //time
    unsigned long current_millis();
    void add_time(int seconds);
    void add_time() {add_time(1);};
    void sub_time(int seconds);
    void sub_time() {sub_time(1);};  
    void stop_or_start_time();
    void stop_time();
    void start_time();
    
    //refresh
    unsigned long refresh(unsigned long current_mills);
    unsigned long refresh() {return refresh(0);};
    
};

#endif
